<template>
  <div class="playlist-box">
    <div class="playlist-head">
      <div class="playlist-head-img">
        <img :src="data.playListImg" />
      </div>
      <div class="playlist-head-introduce">
        <h1>{{ data.playListName }}</h1>
        <div class="playlist-head-name">
          <div></div>
          <a href="javascript:;">{{ data.playListNickName }}</a>
        </div>
        <div class="playlist-head-title">
          <span>标签：</span>
          <a href="javascript:;" v-for="item in data.playListTags">{{
            item
          }}</a>
        </div>
        <div class="playlist-head-span">
          <span>播放量:{{ data.playListCount }}万</span>
          <span>收藏:{{ data.playListSub }}万</span>
        </div>
        <div class="playlist-head-button">
          <button>
            <div class="button-1"></div>
            播放全部
          </button>
          <button>
            <div class="button-2"></div>
            收藏
          </button>
          <button>
            <div class="button-3"></div>
            评论
          </button>
          <button>
            <div class="button-4"></div>
            更多
          </button>
        </div>
      </div>
    </div>
    <div class="playlist-body">
      <div class="playlist-songitem">
        <ul class="playlist-songlist-tetle tetleone">
          <li class="songlist-number"></li>
          <li class="songlist-songname">歌曲</li>
          <li class="songlist-artist">歌手</li>
          <li class="songlist-album">专辑</li>
          <li class="songlist-time">时长</li>
        </ul>
        <ul
          class="playlist-songlist-tetle"
          v-for="(item, index) in data.playSong"
          :key="item.id"
          @mouseenter="mouseenterSong($event)"
          @mouseleave="mouseleaveSong"
        >
          <li class="songlist-number">{{ index + 1 }}</li>
          <li class="songlist-songname">
            <a href="javascript:;">{{ item.name }}</a>

            <div
              class="songlist-songname-hover"
              v-if="item.id == data.songNameId ? data.songListMous : ''"
            >
              <div></div>
              <div></div>
              <div></div>
            </div>
          </li>
          <li class="songlist-artist">
            <a href="javascript:;" v-for="item1 in item.ar" :key="item1.id"
              >{{ item1.name }}
            </a>
          </li>
          <li class="songlist-album">
            <a href="javascript:;">{{ item.al.name }}</a>
          </li>
          <li class="songlist-time">
            <p href="javascript:;">{{ item.dt }}</p>
          </li>
        </ul>
        <div class="recommend-song-button">
          <div>
            <h3>查看更多内容，请下载客户端</h3>
          </div>
          <div>
            <button>立即下载</button>
          </div>
        </div>
      </div>

      <div class="playlist-synopsis">
        <h3>简介</h3>
        <h4>
          {{ data.playDescription }}
        </h4>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "PlayList",
};
</script>

<script setup>
import { getPlayList, getPlaysong } from "./playlist-request";
import { useRoute, useRouter } from "vue-router";
import { onMounted, reactive } from "vue";
const data = reactive({
  playListId: "",
  playListImg: "",
  playListName: "",
  playListNickName: "",
  playListTags: {},
  playListCount: "",
  playListSub: "",
  playDescription: "",
  playSong: {},
  playSongName: "",
  playSongNickName: "",
  songListMous: false,
  songNameId: "",
});

const route = useRoute();

const getPlayListAll = async (id) => {
  const res = await getPlayList(id);
  data.playListImg = res.playlist.coverImgUrl;
  data.playListName = res.playlist.name;
  data.playListNickName = res.playlist.creator.nickname;
  data.playDescription = res.playlist.description;
  data.playListTags = res.playlist.tags;
  data.playListCount = Math.ceil(res.playlist.playCount / 10000);
  data.playListSub = Math.ceil(res.playlist.subscribedCount / 10000);
};

const mouseenterSong = (e) => {
  data.songListMous = true;
  data.songNameId = e.target.__vnode.key;
};

const mouseleaveSong = () => {
  data.songListMous = false;
};

const getPlaysongAll = async (id, num, songid) => {
  const res = await getPlaysong(id, num);
  data.playSong = res.songs.map((item) => {
    //转换时间（s转时分秒）
    // let hour = parseInt(s / 3600); //小时
    // let minutes = s - hour * 3600;
    let minute = parseInt(item.dt / 60000); // 分钟
    let seconds = parseInt(item.dt - minute * 60000) / 10000;
    let second = parseInt(seconds);
    if (minute < 10) {
      minute = "0" + minute;
    }
    if (second < 100) {
      second = "0" + second;
    }
    const dt = minute + ":" + second;
    const { name, ar, al, id } = item;
    return { name, ar, al, id, dt };
  });
};

onMounted(() => {
  console.log(route.query.playListId);
  getPlayListAll(route.query.playListId);
  getPlaysongAll(route.query.playListId, 10);
  window.scrollTo(0, 0);
});
</script>

<style scoped>
.playlist-box {
  background-color: #fafafa;
}
.playlist-head {
  width: 1200px;
  display: flex;
  justify-content: center;
  margin: 0 auto;
}

.playlist-head-img img {
  display: flex;
  width: 250px;
  height: 250px;
  margin: 40px 0;
}

.playlist-head-introduce {
  display: flex;
  flex-direction: column;
  width: 895px;
  height: 250px;
  padding: 40px 40px 0 55px;
}

.playlist-head-introduce h1 {
  padding-top: 14px;
}

.playlist-head-name {
  display: flex;
  height: 27px;
  align-items: center;
}

.playlist-head-name div {
  width: 16px;
  height: 16px;
  background: url(./img/3.png);
  background-position: -20px -240px;
  margin: 5px 7px 0 0;
}

.playlist-head-name a {
  display: block;
  font-size: 16px;
  height: 27px;
  line-height: 27px;
  text-decoration: none;
}

.playlist-head-name a:hover {
  color: #6acb9b;
}
.playlist-head-introduce h1 {
  height: 50px;
  font-size: 31px;
  font-weight: normal;
}

.playlist-head-title {
  height: 27px;
  line-height: 27px;
  font-size: 14px;
}

.playlist-head-span {
  display: flex;
  flex-direction: column;
  line-height: 27px;
  font-size: 14px;
}

.playlist-head-title a {
  text-decoration: none;
  padding-right: 9px;
  color: #000;
}

.playlist-head-button {
  display: flex;
}
.playlist-head-title a:hover {
  color: #6acb9b;
}

.playlist-head-button {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
}

.playlist-head-button button {
  font-size: 14px;
  line-height: 38px;
  display: flex;
  height: 38px;
  margin: auto 0;
  justify-content: center;
  align-items: center;
  margin-right: 6px;
  padding: 0 28px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  background-color: #fafafa;
  border: 1px solid #c9c9c9;
}

.playlist-head-button button:hover {
  background-color: #ededed;
}

.playlist-head-button button:first-child:hover {
  background-color: #2caf6f;
}

.playlist-head-button button:first-child {
  background-color: #31c27c;
  color: #fff;
  border: 1px solid #31c27c;
}

.playlist-head-button div {
  height: 16px;
  width: 13px;
  padding-right: 6px;
}

.button-1 {
  background: url(./img/3.png);
  background-position: -80px -220px;
}
.button-2 {
  background: url(./img/3.png);
  background-position: -60px 0;
}
.button-3 {
  background: url(./img/3.png);
  background-position: -140px -120px;
}
.button-4 {
  background: url(./img/3.png);
  background-position: -20px -80px;
}

/* 歌曲列表以及简介 */

.playlist-body {
  display: flex;
  margin: 0 auto;
  justify-content: center;
  width: 1200px;
}

.playlist-songitem {
  margin-right: 50px;
  flex: 1 1 auto;
  /* border: 1px solid #000; */
}
.playlist-synopsis {
  width: 290px;
}

.playlist-synopsis h3 {
  font-size: 14px;
}
.playlist-synopsis h4 {
  font-weight: normal;
  font-size: 14px;
  line-height: 24px;
}

.playlist-songlist {
  display: flex;
  height: 50px;
  font-size: 14px;
}

.playlist-songlist-tetle {
  display: flex;
  height: 50px;
  font-size: 14px;
}

.playlist-songitem .tetleone {
  background-color: #fbfbfd !important;
}
.playlist-songlist-tetle:nth-of-type(odd) {
  background-color: #fafafa;
}
.playlist-songlist-tetle:nth-of-type(even) {
  background-color: #f7f7f7;
}

.playlist-songlist-tetle li {
  margin: auto 0;
  padding-left: 30px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-songlist-tetle li a:hover {
  color: #6acb9b;
  text-decoration: none;
}

.playlist-songlist-tetle li a {
  color: #000;
}

.playlist-songlist-tetle li a:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.songlist-number {
  width: 36px;
  color: #666;
}
.songlist-songname {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 385px;
}

.songlist-songname a {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.songlist-songname .songlist-songname-hover {
  display: flex;
  height: 36px;
  width: 138px;
  /* flex-direction: column; */
  justify-content: space-between;
  align-items: center;
}

.songlist-songname .songlist-songname-hover div:nth-child(1) {
  width: 36px;
  height: 36px;
  background-image: url(./img/4.png);
  background-size: 200px 320px;
  background-position: 0px 0px;
}
.songlist-songname .songlist-songname-hover div:nth-child(2) {
  width: 36px;
  height: 36px;
  background-image: url(./img/4.png);
  background-size: 200px 320px;
  background-position: 0px -80px;
}
.songlist-songname .songlist-songname-hover div:nth-child(3) {
  width: 36px;
  height: 36px;
  background-image: url(./img/4.png);
  background-size: 200px 320px;
  background-position: 0px 40px;
}

.songlist-songname .songlist-songname-hover div:nth-child(1):hover {
  background-position: -40px 0px;
}
.songlist-songname .songlist-songname-hover div:nth-child(2):hover {
  background-position: -40px -80px;
}
.songlist-songname .songlist-songname-hover div:nth-child(3):hover {
  background-position: -40px 40px;
}

.songlist-artist {
  display: flex;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 140px;
}
.songlist-artist a {
  height: 50px;
  line-height: 50px;
}

.songlist-artist a:nth-child(2)::before {
  content: "/";
  right: 0;
}
.songlist-artist a:nth-child(3)::before {
  content: "/";
  right: 0;
}
.songlist-album {
  margin-right: 40px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 140px;
}

.songlist-time {
  width: 50px;
}
.playlist-songlist-tetle .songlist-time p {
  color: #666;
}
.recommend-song-button {
  display: flex;
  justify-content: center;
  height: 90px;
  flex-direction: column;
  align-items: center;
  padding-top: 100px;
  padding-bottom: 22px;
}

.recommend-song-button h3 {
  font-size: 18px;
}

.recommend-song-button button {
  width: 175px;
  height: 40px;
  border-radius: 40px;
  font-size: 16px;
  color: #fff;
  background-color: #31c27c;
  border: none;
  margin-top: 20px;
  cursor: pointer;
}

.recommend-song-button button:hover {
  background-color: #2caf6f;
}
</style>
